home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / SWAP.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  4KB  |  176 lines

  1. #ifndef _LINUX_SWAP_H
  2. #define _LINUX_SWAP_H
  3.  
  4. #include <asm/page.h>
  5.  
  6. #define SWAP_FLAG_PREFER    0x8000    /* set if swap priority specified */
  7. #define SWAP_FLAG_PRIO_MASK    0x7fff
  8. #define SWAP_FLAG_PRIO_SHIFT    0
  9.  
  10. #define MAX_SWAPFILES 8
  11.  
  12. union swap_header {
  13.     struct 
  14.     {
  15.         char reserved[PAGE_SIZE - 10];
  16.         char magic[10];
  17.     } magic;
  18.     struct 
  19.     {
  20.         char         bootbits[1024];    /* Space for disklabel etc. */
  21.         unsigned int version;
  22.         unsigned int last_page;
  23.         unsigned int nr_badpages;
  24.         unsigned int padding[125];
  25.         unsigned int badpages[1];
  26.     } info;
  27. };
  28.  
  29. #ifdef __KERNEL__
  30.  
  31. /*
  32.  * Max bad pages in the new format..
  33.  */
  34. #define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x)
  35. #define MAX_SWAP_BADPAGES \
  36.     ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int))
  37.  
  38. #undef DEBUG_SWAP
  39.  
  40. #include <asm/atomic.h>
  41.  
  42. #define SWP_USED    1
  43. #define SWP_WRITEOK    3
  44.  
  45. #define SWAP_CLUSTER_MAX 32
  46.  
  47. #define SWAP_MAP_MAX    0x7fff
  48. #define SWAP_MAP_BAD    0x8000
  49.  
  50. struct swap_info_struct {
  51.     unsigned int flags;
  52.     kdev_t swap_device;
  53.     struct dentry * swap_file;
  54.     unsigned short * swap_map;
  55.     unsigned char * swap_lockmap;
  56.     unsigned int lowest_bit;
  57.     unsigned int highest_bit;
  58.     unsigned int cluster_next;
  59.     unsigned int cluster_nr;
  60.     int prio;            /* swap priority */
  61.     int pages;
  62.     unsigned long max;
  63.     int next;            /* next entry on swap list */
  64. };
  65.  
  66. extern int nr_swap_pages;
  67. extern int nr_free_pages;
  68. extern atomic_t nr_async_pages;
  69. extern struct inode swapper_inode;
  70. extern unsigned long page_cache_size;
  71. extern int buffermem;
  72.  
  73. /* Incomplete types for prototype declarations: */
  74. struct task_struct;
  75. struct vm_area_struct;
  76. struct sysinfo;
  77.  
  78. /* linux/ipc/shm.c */
  79. extern int shm_swap (int, int);
  80.  
  81. /* linux/mm/swap.c */
  82. extern void swap_setup (void);
  83.  
  84. /* linux/mm/vmscan.c */
  85. extern int try_to_free_pages(unsigned int gfp_mask);
  86.  
  87. /* linux/mm/page_io.c */
  88. extern void rw_swap_page(int, unsigned long, char *, int);
  89. extern void rw_swap_page_nocache(int, unsigned long, char *);
  90. extern void rw_swap_page_nolock(int, unsigned long, char *, int);
  91. extern void swap_after_unlock_page (unsigned long entry);
  92.  
  93. /* linux/mm/page_alloc.c */
  94. extern void swap_in(struct task_struct *, struct vm_area_struct *,
  95.             pte_t *, unsigned long, int);
  96.  
  97.  
  98. /* linux/mm/swap_state.c */
  99. extern void show_swap_cache_info(void);
  100. extern int add_to_swap_cache(struct page *, unsigned long);
  101. extern int swap_duplicate(unsigned long);
  102. extern int swap_check_entry(unsigned long);
  103. struct page * lookup_swap_cache(unsigned long);
  104. extern struct page * read_swap_cache_async(unsigned long, int);
  105. #define read_swap_cache(entry) read_swap_cache_async(entry, 1);
  106. extern int FASTCALL(swap_count(unsigned long));
  107. /*
  108.  * Make these inline later once they are working properly.
  109.  */
  110. extern void delete_from_swap_cache(struct page *page);
  111. extern void free_page_and_swap_cache(unsigned long addr);
  112.  
  113. /* linux/mm/swapfile.c */
  114. extern unsigned int nr_swapfiles;
  115. extern struct swap_info_struct swap_info[];
  116. void si_swapinfo(struct sysinfo *);
  117. unsigned long get_swap_page(void);
  118. extern void FASTCALL(swap_free(unsigned long));
  119. struct swap_list_t {
  120.     int head;    /* head of priority-ordered swapfile list */
  121.     int next;    /* swapfile to be used next */
  122. };
  123. extern struct swap_list_t swap_list;
  124. asmlinkage int sys_swapoff(const char *);
  125. asmlinkage int sys_swapon(const char *, int);
  126.  
  127. /*
  128.  * vm_ops not present page codes for shared memory.
  129.  *
  130.  * Will go away eventually..
  131.  */
  132. #define SHM_SWP_TYPE 0x20
  133.  
  134. /*
  135.  * swap cache stuff (in linux/mm/swap_state.c)
  136.  */
  137.  
  138. #define SWAP_CACHE_INFO
  139.  
  140. #ifdef SWAP_CACHE_INFO
  141. extern unsigned long swap_cache_add_total;
  142. extern unsigned long swap_cache_del_total;
  143. extern unsigned long swap_cache_find_total;
  144. extern unsigned long swap_cache_find_success;
  145. #endif
  146.  
  147. extern inline unsigned long in_swap_cache(struct page *page)
  148. {
  149.     if (PageSwapCache(page))
  150.         return page->offset;
  151.     return 0;
  152. }
  153.  
  154. /*
  155.  * Work out if there are any other processes sharing this page, ignoring
  156.  * any page reference coming from the swap cache, or from outstanding
  157.  * swap IO on this page.  (The page cache _does_ count as another valid
  158.  * reference to the page, however.)
  159.  */
  160. static inline int is_page_shared(struct page *page)
  161. {
  162.     unsigned int count;
  163.     if (PageReserved(page))
  164.         return 1;
  165.     count = atomic_read(&page->count);
  166.     if (PageSwapCache(page))
  167.         count += swap_count(page->offset) - 2;
  168.     if (PageFreeAfter(page))
  169.         count--;
  170.     return  count > 1;
  171. }
  172.  
  173. #endif /* __KERNEL__*/
  174.  
  175. #endif /* _LINUX_SWAP_H */
  176.